TARGET ?= arm-none-eabi

MY_DIR := $(dir $(lastword $(MAKEFILE_LIST)))

AS := $(TARGET)-as
CC := $(TARGET)-gcc

ARCH := armv6
CFLAGS += -march=$(ARCH) -I$(MY_DIR)system

ifdef PROGRAM
all: $(PROGRAM).bin
$(PROGRAM).o: $(MY_DIR)/system/myarm.ld $(OBJECTS)
	$(CC) -o $@ -T $^ -nostdlib -Wl,--build-id=none -L$(MY_DIR)/system -lmyarm -lgcc
endif

.PRECIOUS: %.o

%.bin: %.o
	$(TARGET)-objcopy -O binary -j .text -j .rodata -j .data $< $@
#%-dram.bin: %.o
#	$(TARGET)-objcopy -O binary -j .dram.text -j .dram.rodata -j .dram.data $< $@
%.dis: %.o
	$(TARGET)-objdump -d $< > $@

.PHONY: all
all:

.PHONY: clean
clean:
	rm -f *.o *.bin *.dis
